<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    let book = {
        title: 'Everything\'s all right',
        authors: [
            'to the moon',
            'back here'
        ],
        edition: 4,
        year: 2019
    }

    /*
        第二个参数,表示只转换哪个
             (number|string)[] | null
             或者(this:any, key:string, value:any ) =>any
     */

    let jsonText = JSON.stringify(book,['title','edition']);
    // {"title":"Everything's all right","edition":4}
    console.log(jsonText)
    
    // 相当于自定义
   let nextJson =  JSON.stringify(book,(key,value) =>{
        switch (key) {
            case "authors":
                return "authors-"
            case "year":
                return 6666
            default:
                return value
        }
    })
    console.log(nextJson)
    
    
    // 第三个参数  数字控制缩进,最大为10,
    //           字符相当于前面加上指定的字符
    console.log(JSON.stringify(book,null,4))// 4个缩进
    
    
</script>
</body>
</html>